import React, { Component } from "react";
import "./index.less";
import Footer from "../../components/Footer";
import Top from "./Top";
import Scenic from "./Scenic";
import City from "./City";
import List from "./List";
import {$houseScene,$houseCity,$houseRecommend} from 'api/index'

class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      // 景点列表
      sceneList:[],
      // 城市列表
      cityList:[],
      // 房子列表
      houseList: []
    };
    this.getScenicList = this.getScenicList.bind(this);
    this.getCityList = this.getCityList.bind(this);
  }

  componentDidMount() {
    // 获取景点列表
    this.getScenicList();
    // 获取景点列表
    this.getCityList();
    // 获取目的地列表
    this.getHouseList();
  }

  // 获取景点列表
  getScenicList() {
    $houseScene().then(res=> { 
      this.setState({
        sceneList: res.result
      })
    })
  } 

  // 获取城市列表
  getCityList() {
    $houseCity().then(res=> { 
      this.setState({
        cityList: res.result
      })
    })
  }

  // 获取城市列表
  getHouseList() {
    $houseRecommend().then(res=> { 
      this.setState({
        houseList: res.result
      })
    })
  }

  render() {
    return (
      <div className="home-index">
        {/* 头部 */}
        <Top />

        {/* 景点 */}
        <Scenic list={this.state.sceneList}/>

        {/* 城市 */}
        <City list={this.state.cityList}/>

        {/* 列表 */}
        <List list={this.state.houseList}/>

        <Footer activeIndex={1} />
      </div>
    );
  }
}

export default Index;
